package suites.page {
	import suites.stub.AsyncRequestPageStubEvent;

	import org.flexunit.asserts.assertEquals;
	import org.splink.deepsplink.boot.IDeepsplinkFacade;
	import org.splink.deepsplink.page.params.PageParameter;

	/**
	 * Tests "hide-initshow-finalize" requestbuilder with asyncronous initializing, showing and hiding pages
	 * 
	 * @author Max Kugland
	 */
	public class AsyncGotoPageTest extends AsyncGotoPageBase {
		

		[Test (async)]
		public function autoHome() : void {
			handleAsync(800);
			createFacade();
			
			getPage("1").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("initialize-root", _history[0]);
				assertEquals("show-root", _history[1]);
				assertEquals("initialize-1", _history[2]);
				assertEquals("show-1", _history[3]);
				assertEquals(4, _history.length);
				complete();
			});
		}

		[Test (async)]
		public function showLevel1() : void {
			handleAsync(1000);
			
			var facade : IDeepsplinkFacade = createFacade();
			getPage("1").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				asyncGotoPage(facade.navigationCommand, "2");
			});
			
			getPage("1").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-1", _history[0]);
				assertEquals("initialize-2", _history[1]);
				assertEquals("show-2", _history[2]);
				assertEquals("finalize-1", _history[3]);
				assertEquals(4, _history.length);
				complete();
			});
		}


		[Test (async)]
		public function showLevel2() : void {
			handleAsync(1200);
			
			var facade : IDeepsplinkFacade = createFacade();
			getPage("1").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				asyncGotoPage(facade.navigationCommand, "3");
			});
			
			getPage("1").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-1", _history[0]);
				assertEquals("initialize-2", _history[1]);
				assertEquals("show-2", _history[2]);
				assertEquals("initialize-3", _history[3]);
				assertEquals("show-3", _history[4]);
				assertEquals("finalize-1", _history[5]);
				assertEquals(6, _history.length);
				complete();
			});
		}


		[Test (async)]
		public function showLevel3() : void {
			handleAsync(1400);
			
			var facade : IDeepsplinkFacade = createFacade();
			getPage("1").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				asyncGotoPage(facade.navigationCommand, "8");
			});
			
			getPage("1").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-1", _history[0]);
				assertEquals("initialize-5", _history[1]);
				assertEquals("show-5", _history[2]);
				assertEquals("initialize-6", _history[3]);
				assertEquals("show-6", _history[4]);
				assertEquals("initialize-8", _history[5]);
				assertEquals("show-8", _history[6]);
				assertEquals("finalize-1", _history[7]);
				assertEquals(8, _history.length);
				complete();
			});
		}


		[Test (async)]
		public function showLevel4() : void {
			handleAsync(1600);
			
			var facade : IDeepsplinkFacade = createFacade();
			getPage("1").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				asyncGotoPage(facade.navigationCommand, "10");
			});
			
			getPage("1").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-1", _history[0]);
				assertEquals("initialize-5", _history[1]);
				assertEquals("show-5", _history[2]);
				assertEquals("initialize-6", _history[3]);
				assertEquals("show-6", _history[4]);
				assertEquals("initialize-8", _history[5]);
				assertEquals("show-8", _history[6]);
				assertEquals("initialize-10", _history[7]);
				assertEquals("show-10", _history[8]);
				assertEquals("finalize-1", _history[9]);
				assertEquals(10, _history.length);
				complete();
			});
		}

		[Test (async)]
		public function navigateLevel1() : void {
			handleAsync(2000);
			
			var facade : IDeepsplinkFacade = createFacade();
			getPage("1").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				asyncGotoPage(facade.navigationCommand, "2");
			});
			
			getPage("1").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-1", _history[0]);
				assertEquals("initialize-2", _history[1]);
				assertEquals("show-2", _history[2]);
				assertEquals("finalize-1", _history[3]);
				assertEquals(4, _history.length);
				asyncGotoPage(facade.navigationCommand, "5");
			});
			
			getPage("2").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-2", _history[0]);
				assertEquals("initialize-5", _history[1]);
				assertEquals("show-5", _history[2]);
				assertEquals("finalize-2", _history[3]);
				assertEquals(4, _history.length);
				asyncGotoPage(facade.navigationCommand, "1");
			});
			
			getPage("5").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-5", _history[0]);
				assertEquals("initialize-1", _history[1]);
				assertEquals("show-1", _history[2]);
				assertEquals("finalize-5", _history[3]);
				assertEquals(4, _history.length);
				complete();
			});
		}

		[Test (async)]
		public function navigateLevel2() : void {
			handleAsync(2000);
			
			var facade : IDeepsplinkFacade = createFacade();
			getPage("1").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				asyncGotoPage(facade.navigationCommand, "3");
			});
			
			getPage("1").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-1", _history[0]);
				assertEquals("initialize-2", _history[1]);
				assertEquals("show-2", _history[2]);
				assertEquals("initialize-3", _history[3]);
				assertEquals("show-3", _history[4]);
				assertEquals("finalize-1", _history[5]);
				assertEquals(6, _history.length);
				asyncGotoPage(facade.navigationCommand, "4");
			});
			
			getPage("3").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-3", _history[0]);
				assertEquals("initialize-4", _history[1]);
				assertEquals("show-4", _history[2]);
				assertEquals("finalize-3", _history[3]);
				assertEquals(4, _history.length);
				asyncGotoPage(facade.navigationCommand, "3");
			});
			
			
			getPage("4").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-4", _history[0]);
				assertEquals("initialize-3", _history[1]);
				assertEquals("show-3", _history[2]);
				assertEquals("finalize-4", _history[3]);
				assertEquals(4, _history.length);
				complete();
			});
			
		}

		[Test (async)]
		public function navigateLevel3() : void {
			handleAsync(2000);
			
			var facade : IDeepsplinkFacade = createFacade();
			getPage("1").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				asyncGotoPage(facade.navigationCommand, "7");
			});
			
			getPage("1").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-1", _history[0]);
				assertEquals("initialize-5", _history[1]);
				assertEquals("show-5", _history[2]);
				assertEquals("initialize-6", _history[3]);
				assertEquals("show-6", _history[4]);
				assertEquals("initialize-7", _history[5]);
				assertEquals("show-7", _history[6]);
				assertEquals("finalize-1", _history[7]);
				assertEquals(8, _history.length);
				asyncGotoPage(facade.navigationCommand, "8");	
			});
			
			getPage("7").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-7", _history[0]);
				assertEquals("initialize-8", _history[1]);
				assertEquals("show-8", _history[2]);
				assertEquals("finalize-7", _history[3]);
				assertEquals(4, _history.length);
				asyncGotoPage(facade.navigationCommand, "7");
			});
			
			getPage("8").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-8", _history[0]);
				assertEquals("initialize-7", _history[1]);
				assertEquals("show-7", _history[2]);
				assertEquals("finalize-8", _history[3]);
				assertEquals(4, _history.length);
				complete();
			});
		}

		[Test (async)]
		public function navigateLevel1And2() : void {
			handleAsync(2000);
			
			var facade : IDeepsplinkFacade = createFacade();
			getPage("1").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				asyncGotoPage(facade.navigationCommand, "3");
			});
			
			getPage("1").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-1", _history[0]);
				assertEquals("initialize-2", _history[1]);
				assertEquals("show-2", _history[2]);
				assertEquals("initialize-3", _history[3]);
				assertEquals("show-3", _history[4]);
				assertEquals("finalize-1", _history[5]);
				assertEquals(6, _history.length);
				asyncGotoPage(facade.navigationCommand, "5");
			});
			
			getPage("2").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-3", _history[0]);
				assertEquals("hide-2", _history[1]);
				assertEquals("initialize-5", _history[2]);
				assertEquals("show-5", _history[3]);				assertEquals("finalize-3", _history[4]);				assertEquals("finalize-2", _history[5]);
				assertEquals(6, _history.length);
				asyncGotoPage(facade.navigationCommand, "4");
			});
			
			getPage("5").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-5", _history[0]);
				assertEquals("initialize-2", _history[1]);
				assertEquals("show-2", _history[2]);
				assertEquals("initialize-4", _history[3]);
				assertEquals("show-4", _history[4]);
				assertEquals("finalize-5", _history[5]);
				assertEquals(6, _history.length);
				complete();
			});		}

		[Test (async)]
		public function navigateLevel1And3() : void {
			handleAsync(2000);
			
			var facade : IDeepsplinkFacade = createFacade();
			getPage("1").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				asyncGotoPage(facade.navigationCommand, "7");
			});
			
			getPage("1").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-1", _history[0]);
				assertEquals("initialize-5", _history[1]);
				assertEquals("show-5", _history[2]);
				assertEquals("initialize-6", _history[3]);
				assertEquals("show-6", _history[4]);
				assertEquals("initialize-7", _history[5]);
				assertEquals("show-7", _history[6]);
				assertEquals("finalize-1", _history[7]);
				assertEquals(8, _history.length);
				asyncGotoPage(facade.navigationCommand, "5");
			});
			
			getPage("6").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-7", _history[0]);
				assertEquals("hide-6", _history[1]);
				assertEquals("finalize-7", _history[2]);
				assertEquals("finalize-6", _history[3]);
				assertEquals(4, _history.length);
				asyncGotoPage(facade.navigationCommand, "8");
			});
			
			getPage("8").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("initialize-6", _history[0]);
				assertEquals("show-6", _history[1]);
				assertEquals("initialize-8", _history[2]);
				assertEquals("show-8", _history[3]);
				assertEquals(4, _history.length);
				asyncGotoPage(facade.navigationCommand, "1");
			});
			
			getPage("5").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-8", _history[0]);
				assertEquals("hide-6", _history[1]);
				assertEquals("hide-5", _history[2]);
				assertEquals("initialize-1", _history[3]);				assertEquals("show-1", _history[4]);				assertEquals("finalize-8", _history[5]);				assertEquals("finalize-6", _history[6]);				assertEquals("finalize-5", _history[7]);
				assertEquals(8, _history.length);
				complete();
			});
		}

		[Test (async)]
		public function navigateLevel1And2And3() : void {
			handleAsync(2000);
			
			var facade : IDeepsplinkFacade = createFacade();
			getPage("1").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				asyncGotoPage(facade.navigationCommand, "8");
			});
			
			getPage("1").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-1", _history[0]);
				assertEquals("initialize-5", _history[1]);
				assertEquals("show-5", _history[2]);
				assertEquals("initialize-6", _history[3]);
				assertEquals("show-6", _history[4]);
				assertEquals("initialize-8", _history[5]);
				assertEquals("show-8", _history[6]);
				assertEquals("finalize-1", _history[7]);
				assertEquals(8, _history.length);
				asyncGotoPage(facade.navigationCommand, "6");
			});
			
			getPage("8").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-8", _history[0]);
				assertEquals("finalize-8", _history[1]);
				assertEquals(2, _history.length);
				asyncGotoPage(facade.navigationCommand, "7");
			});
			
			getPage("7").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("initialize-7", _history[0]);
				assertEquals("show-7", _history[1]);
				assertEquals(2, _history.length);
				asyncGotoPage(facade.navigationCommand, "3");
			});
			
			getPage("5").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-7", _history[0]);
				assertEquals("hide-6", _history[1]);				assertEquals("hide-5", _history[2]);				assertEquals("initialize-2", _history[3]);				assertEquals("show-2", _history[4]);				assertEquals("initialize-3", _history[5]);				assertEquals("show-3", _history[6]);				assertEquals("finalize-7", _history[7]);				assertEquals("finalize-6", _history[8]);				assertEquals("finalize-5", _history[9]);
				assertEquals(10, _history.length);
				asyncGotoPage(facade.navigationCommand, "4");
			});
			
			getPage("3").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-3", _history[0]);
				assertEquals("initialize-4", _history[1]);
				assertEquals("show-4", _history[2]);
				assertEquals("finalize-3", _history[3]);
				assertEquals(4, _history.length);
				asyncGotoPage(facade.navigationCommand, "1");
			});
			
			getPage("2").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-4", _history[0]);
				assertEquals("hide-2", _history[1]);
				assertEquals("initialize-1", _history[2]);
				assertEquals("show-1", _history[3]);				assertEquals("finalize-4", _history[4]);				assertEquals("finalize-2", _history[5]);
				assertEquals(6, _history.length);
				complete();
			});
		}

		[Test (async)]
		public function showLevel1Params() : void {
			handleAsync(2000);
			
			var facade : IDeepsplinkFacade = createFacade();
			getPage("1").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				asyncGotoPage(facade.navigationCommand, "2", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			});
			
			getPage("1").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-1", _history[0]);				assertEquals("params-root-2", _history[1]);				assertEquals("params-2-2", _history[2]);
				assertEquals("initialize-2", _history[3]);
				assertEquals("show-2", _history[4]);
				assertEquals("finalize-1", _history[5]);
				assertEquals(6, _history.length);
				complete();
			});
		}

		[Test (async)]
		public function showLevel2Params() : void {
			handleAsync(2000);
			
			var facade : IDeepsplinkFacade = createFacade();
			getPage("1").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				asyncGotoPage(facade.navigationCommand, "3", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			});
			
			getPage("1").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-1", _history[0]);
				assertEquals("params-root-2", _history[1]);
				assertEquals("params-2-2", _history[2]);
				assertEquals("initialize-2", _history[3]);
				assertEquals("show-2", _history[4]);
				assertEquals("params-3-2", _history[5]);
				assertEquals("initialize-3", _history[6]);
				assertEquals("show-3", _history[7]);
				assertEquals("finalize-1", _history[8]);
				assertEquals(9, _history.length);
				complete();
			});
		}

		[Test (async)]
		public function showLevel4Params() : void {
			handleAsync(2000);
			
			var facade : IDeepsplinkFacade = createFacade();
			getPage("1").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				asyncGotoPage(facade.navigationCommand, "10", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			});
			
			getPage("1").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-1", _history[0]);
				assertEquals("params-root-2", _history[1]);
				assertEquals("params-5-2", _history[2]);
				assertEquals("initialize-5", _history[3]);
				assertEquals("show-5", _history[4]);
				assertEquals("params-6-2", _history[5]);
				assertEquals("initialize-6", _history[6]);
				assertEquals("show-6", _history[7]);
				assertEquals("params-8-2", _history[8]);
				assertEquals("initialize-8", _history[9]);
				assertEquals("show-8", _history[10]);
				assertEquals("params-10-2", _history[11]);
				assertEquals("initialize-10", _history[12]);
				assertEquals("show-10", _history[13]);
				assertEquals("finalize-1", _history[14]);
				assertEquals(15, _history.length);
				complete();
			});
		}

		[Test (async)]
		public function navigateLevel1Params() : void {
			handleAsync(2000);
			
			var facade : IDeepsplinkFacade = createFacade();
			getPage("1").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				asyncGotoPage(facade.navigationCommand, "2", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);			});
			
			getPage("1").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-1", _history[0]);
				assertEquals("params-root-2", _history[1]);				assertEquals("params-2-2", _history[2]);
				assertEquals("initialize-2", _history[3]);
				assertEquals("show-2", _history[4]);
				assertEquals("finalize-1", _history[5]);
				assertEquals(6, _history.length);
				asyncGotoPage(facade.navigationCommand, "5", [new PageParameter("param1", "hello")]);
			});
			
			getPage("2").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-2", _history[0]);
				assertEquals("params-root-1", _history[1]);
				assertEquals("params-5-1", _history[2]);
				assertEquals("initialize-5", _history[3]);
				assertEquals("show-5", _history[4]);
				assertEquals("finalize-2", _history[5]);
				assertEquals(6, _history.length);
				asyncGotoPage(facade.navigationCommand, "1", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			});
			
			getPage("5").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-5", _history[0]);
				assertEquals("params-root-2", _history[1]);
				assertEquals("params-1-2", _history[2]);
				assertEquals("initialize-1", _history[3]);
				assertEquals("show-1", _history[4]);
				assertEquals("finalize-5", _history[5]);
				assertEquals(6, _history.length);
				complete();
			});
		}

		[Test (async)]
		public function navigateLevel3Params() : void {
			handleAsync(2000);
			
			var facade : IDeepsplinkFacade = createFacade();
			getPage("1").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				asyncGotoPage(facade.navigationCommand, "7", [new PageParameter("param1", "hello")]);			});
			
			getPage("1").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-1", _history[0]);				assertEquals("params-root-1", _history[1]);
				assertEquals("params-5-1", _history[2]);
				assertEquals("initialize-5", _history[3]);
				assertEquals("show-5", _history[4]);
				assertEquals("params-6-1", _history[5]);
				assertEquals("initialize-6", _history[6]);
				assertEquals("show-6", _history[7]);
				assertEquals("params-7-1", _history[8]);
				assertEquals("initialize-7", _history[9]);
				assertEquals("show-7", _history[10]);
				assertEquals("finalize-1", _history[11]);
				assertEquals(12, _history.length);
				asyncGotoPage(facade.navigationCommand, "8", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			});
			
			getPage("7").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-7", _history[0]);
				assertEquals("params-root-2", _history[1]);				assertEquals("params-5-2", _history[2]);				assertEquals("params-6-2", _history[3]);
				assertEquals("params-8-2", _history[4]);
				assertEquals("initialize-8", _history[5]);
				assertEquals("show-8", _history[6]);
				assertEquals("finalize-7", _history[7]);
				assertEquals(8, _history.length);
				// params change
				asyncGotoPage(facade.navigationCommand, "7", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			});
			
			getPage("8").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-8", _history[0]);
				assertEquals("params-7-2", _history[1]);
				assertEquals("initialize-7", _history[2]);
				assertEquals("show-7", _history[3]);
				assertEquals("finalize-8", _history[4]);
				assertEquals(5, _history.length);
				complete();
			});
		}

		[Test (async)]
		public function navigateLevel1And2Params() : void {
			handleAsync(2000);
			
			var facade : IDeepsplinkFacade = createFacade();
			getPage("1").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				asyncGotoPage(facade.navigationCommand, "3", [new PageParameter("param1", "hello")]);
			});
			
			getPage("1").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-1", _history[0]);
				assertEquals("params-root-1", _history[1]);
				assertEquals("params-2-1", _history[2]);
				assertEquals("initialize-2", _history[3]);
				assertEquals("show-2", _history[4]);
				assertEquals("params-3-1", _history[5]);
				assertEquals("initialize-3", _history[6]);
				assertEquals("show-3", _history[7]);
				assertEquals("finalize-1", _history[8]);
				assertEquals(9, _history.length);
				// params change
				asyncGotoPage(facade.navigationCommand, "5", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			});
			
			getPage("2").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-3", _history[0]);
				assertEquals("hide-2", _history[1]);
				assertEquals("params-root-2", _history[2]);
				assertEquals("params-5-2", _history[3]);
				assertEquals("initialize-5", _history[4]);
				assertEquals("show-5", _history[5]);
				assertEquals("finalize-3", _history[6]);
				assertEquals("finalize-2", _history[7]);
				assertEquals(8, _history.length);
				asyncGotoPage(facade.navigationCommand, "4", [new PageParameter("param1", "hello")]);
			});
			
			getPage("5").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-5", _history[0]);
				assertEquals("params-root-1", _history[1]);				assertEquals("params-2-1", _history[2]);
				assertEquals("initialize-2", _history[3]);
				assertEquals("show-2", _history[4]);
				assertEquals("params-4-1", _history[5]);
				assertEquals("initialize-4", _history[6]);
				assertEquals("show-4", _history[7]);
				assertEquals("finalize-5", _history[8]);
				assertEquals(9, _history.length);
				complete();
			});
		}

		[Test (async)]
		public function navigateLevel1And3Params() : void {
			handleAsync(2000);
			
			var facade : IDeepsplinkFacade = createFacade();
			getPage("1").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				asyncGotoPage(facade.navigationCommand, "7", [new PageParameter("param1", "hello")]);
			});
			
			getPage("1").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-1", _history[0]);
				assertEquals("params-root-1", _history[1]);
				assertEquals("params-5-1", _history[2]);
				assertEquals("initialize-5", _history[3]);
				assertEquals("show-5", _history[4]);
				assertEquals("params-6-1", _history[5]);
				assertEquals("initialize-6", _history[6]);
				assertEquals("show-6", _history[7]);
				assertEquals("params-7-1", _history[8]);
				assertEquals("initialize-7", _history[9]);
				assertEquals("show-7", _history[10]);
				assertEquals("finalize-1", _history[11]);
				assertEquals(12, _history.length);
				// params don't change
				asyncGotoPage(facade.navigationCommand, "5", [new PageParameter("param1", "hello")]);
			});
			
			getPage("6").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-7", _history[0]);
				assertEquals("hide-6", _history[1]);
				assertEquals("finalize-7", _history[2]);
				assertEquals("finalize-6", _history[3]);
				assertEquals(4, _history.length);
				asyncGotoPage(facade.navigationCommand, "8", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			});
			
			getPage("8").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("params-root-2", _history[0]);				assertEquals("params-5-2", _history[1]);
				assertEquals("params-6-2", _history[2]);
				assertEquals("initialize-6", _history[3]);
				assertEquals("show-6", _history[4]);
				assertEquals("params-8-2", _history[5]);
				assertEquals("initialize-8", _history[6]);
				assertEquals("show-8", _history[7]);
				assertEquals(8, _history.length);
				// params don't change
				asyncGotoPage(facade.navigationCommand, "1", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			});
			
			getPage("5").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-8", _history[0]);
				assertEquals("hide-6", _history[1]);
				assertEquals("hide-5", _history[2]);
				assertEquals("params-1-2", _history[3]);
				assertEquals("initialize-1", _history[4]);
				assertEquals("show-1", _history[5]);
				assertEquals("finalize-8", _history[6]);
				assertEquals("finalize-6", _history[7]);
				assertEquals("finalize-5", _history[8]);
				assertEquals(9, _history.length);
				complete();
			});
		}

		[Test (async)]
		public function navigateLevel1And2And3Params() : void {
			handleAsync(2000);
			
			var facade : IDeepsplinkFacade = createFacade();
			getPage("1").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				asyncGotoPage(facade.navigationCommand, "8", [new PageParameter("param1", "hello")]);
			});
			
			getPage("1").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-1", _history[0]);
				assertEquals("params-root-1", _history[1]);
				assertEquals("params-5-1", _history[2]);
				assertEquals("initialize-5", _history[3]);
				assertEquals("show-5", _history[4]);
				assertEquals("params-6-1", _history[5]);
				assertEquals("initialize-6", _history[6]);
				assertEquals("show-6", _history[7]);
				assertEquals("params-8-1", _history[8]);
				assertEquals("initialize-8", _history[9]);
				assertEquals("show-8", _history[10]);
				assertEquals("finalize-1", _history[11]);
				assertEquals(12, _history.length);
				asyncGotoPage(facade.navigationCommand, "6", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			});
			
			getPage("8").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-8", _history[0]);
				assertEquals("params-root-2", _history[1]);
				assertEquals("params-5-2", _history[2]);
				assertEquals("params-6-2", _history[3]);
				assertEquals("finalize-8", _history[4]);
				assertEquals(5, _history.length);
				asyncGotoPage(facade.navigationCommand, "7", [new PageParameter("param1", "hello")]);
			});
			
			getPage("7").register(AsyncRequestPageStubEvent.SHOW, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("params-root-1", _history[0]);				assertEquals("params-5-1", _history[1]);				assertEquals("params-6-1", _history[2]);
				assertEquals("params-7-1", _history[3]);
				assertEquals("initialize-7", _history[4]);
				assertEquals("show-7", _history[5]);
				assertEquals(6, _history.length);
				asyncGotoPage(facade.navigationCommand, "3", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			});
			
			getPage("5").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-7", _history[0]);
				assertEquals("hide-6", _history[1]);
				assertEquals("hide-5", _history[2]);
				assertEquals("params-root-2", _history[3]);
				assertEquals("params-2-2", _history[4]);
				assertEquals("initialize-2", _history[5]);
				assertEquals("show-2", _history[6]);
				assertEquals("params-3-2", _history[7]);
				assertEquals("initialize-3", _history[8]);
				assertEquals("show-3", _history[9]);
				assertEquals("finalize-7", _history[10]);
				assertEquals("finalize-6", _history[11]);
				assertEquals("finalize-5", _history[12]);
				assertEquals(13, _history.length);
				asyncGotoPage(facade.navigationCommand, "4", [new PageParameter("param1", "hello")]);
			});
			
			getPage("3").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-3", _history[0]);
				assertEquals("params-root-1", _history[1]);
				assertEquals("params-2-1", _history[2]);				assertEquals("params-4-1", _history[3]);
				assertEquals("initialize-4", _history[4]);
				assertEquals("show-4", _history[5]);
				assertEquals("finalize-3", _history[6]);
				assertEquals(7, _history.length);
				asyncGotoPage(facade.navigationCommand, "1", [new PageParameter("param1", "hello")]);
			});
			
			getPage("2").register(AsyncRequestPageStubEvent.FINALIZE, function(e : AsyncRequestPageStubEvent) : void {
				assertEquals("hide-4", _history[0]);
				assertEquals("hide-2", _history[1]);
				assertEquals("params-1-1", _history[2]);
				assertEquals("initialize-1", _history[3]);
				assertEquals("show-1", _history[4]);
				assertEquals("finalize-4", _history[5]);
				assertEquals("finalize-2", _history[6]);
				assertEquals(7, _history.length);
				complete();
			});
		}		
	}
}